﻿Public Class Preferences

    'Authorize Twitter - when successfully authorized, enabled = false
    'reset can enabled = true

    Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
        If AutomaticLogInCheckBox.Checked = True Then
            My.Settings.AutomaticLogIn = True
        Else
            My.Settings.AutomaticLogIn = False
        End If

        If AlwaysOnTopCheckBox.Checked = True Then
            My.Settings.AlwaysOnTop = True
        Else
            My.Settings.AlwaysOnTop = False
        End If

        If MinimizeToTrayCheckBox.Checked = True Then
            My.Settings.MinimizeToTray = True
        Else
            My.Settings.MinimizeToTray = False
        End If

        If MsgBox("The application will restart to save the settings, click OK to restart.") = MsgBoxResult.Ok Then
            Me.Close()
            Application.Restart()
        Else
            Exit Sub
        End If
    End Sub

    Private Sub Preferences_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Settings.AutomaticLogIn = True Then
            AutomaticLogInCheckBox.Checked = True
        Else
            AutomaticLogInCheckBox.Checked = False
        End If

        If My.Settings.AlwaysOnTop = True Then
            AlwaysOnTopCheckBox.Checked = True
        Else
            AlwaysOnTopCheckBox.Checked = False
        End If

        If My.Settings.MinimizeToTray = True Then
            MinimizeToTrayCheckBox.Checked = True
        Else
            MinimizeToTrayCheckBox.Checked = False
        End If
    End Sub

    Private Sub ResetButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetButton.Click
        If MsgBox("Are you sure? This will only reset TumbleDeck, NOT your Tumblr account. TumbleDeck will restart after the process is done.", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
            My.Settings.Reset()
            My.Settings.Email = Nothing
            My.Settings.Password = Nothing
            My.Settings.AlwaysOnTop = False
            My.Settings.OAuthToken = Nothing
            My.Settings.AutomaticLogIn = Nothing
            My.Settings.TumblarityScore = Nothing
            My.Settings.MinimizeToTray = False
            My.Settings.AutomaticLogIn = False
            MsgBox("Done!")
            Me.Close()
            Application.Restart()
        End If
    End Sub
End Class